﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test5_e3_1
{
    public partial class Form1: Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtFile1.Text = openFileDialog.FileName;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtFile2.Text = openFileDialog.FileName;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFile1.Text) || string.IsNullOrEmpty(txtFile2.Text))
            {
                MessageBox.Show("请先选择两个文件！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                string content1 = File.ReadAllText(txtFile1.Text);
                string content2 = File.ReadAllText(txtFile2.Text);
                string mergedContent = content1 + Environment.NewLine + content2; // 合并内容，中间加一个换行符

                // 确保Data目录存在
                string dataDir = Path.Combine(Application.StartupPath, "Data");
                if (!Directory.Exists(dataDir))
                {
                    Directory.CreateDirectory(dataDir);
                }

                string outputFile = Path.Combine(dataDir, $"merged_{DateTime.Now:yyyyMMddHHmmss}.txt");//生成输出名
                File.WriteAllText(outputFile, mergedContent);

                MessageBox.Show($"文件合并成功！\n保存路径: {outputFile}", "成功",
                              MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"合并文件时出错: {ex.Message}", "错误",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


      
    }
}

